package com.huajiao.management_system.service.impl;

import com.huajiao.management_system.bean.prove;
import com.huajiao.management_system.dao.*;
import com.huajiao.management_system.service.proveService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class proveServiceImpl implements proveService {
    @Resource
    private proveMapper provemapper;
    @Resource
    com.huajiao.management_system.dao.competitionResMapper competitionResMapper;
    @Resource
    com.huajiao.management_system.dao.honorResMapper honorResMapper;
    @Resource
    com.huajiao.management_system.dao.paperResMapper paperResMapper;
    @Resource
    com.huajiao.management_system.dao.patentResMapper patentResMapper;
    @Resource
    softwarecopyrightResMapper softwarecopyrightResMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertOne(prove prove) {

        return provemapper.insertall(prove);
    }

    @Override
    public List<String> selectById(Integer id) {
        return provemapper.selectByid(id);
    }

    @Override
    public Boolean deleteImage(String[] url) {
        return provemapper.deleteImage(url) > 0;
    }

    @Override
    public Map<String, Integer> getPie() {
        HashMap map = new HashMap();
        map.put("keyword", "");
        Map<String, Integer> result = new HashMap<>();
        result.put("competitionRes", competitionResMapper.getTotal(map));
        result.put("honorRes", honorResMapper.getTotal(map));
        result.put("paperRes", paperResMapper.getTotal(map));
        result.put("patentRes", patentResMapper.getTotal(map));
        result.put("softwarecopyrightRes", softwarecopyrightResMapper.getTotal(map));
        result.put("total", result.get("competitionRes") +
                result.get("honorRes") +
                result.get("paperRes") +
                result.get("patentRes") +
                result.get("softwarecopyrightRes"));
        return result;
    }

    @Override
    public Map<String, Integer> getLine() {
        HashMap map = new HashMap();
        map.put("keyword", "");
        Calendar date = Calendar.getInstance();
        String year = String.valueOf(date.get(Calendar.YEAR));
        Map<String, Integer> result = new HashMap<>();
        for (int i = 2016; i <= Integer.valueOf(year); i++) {
            map.put("Time", String.valueOf(i));
            int count = 0;
            count = competitionResMapper.getTotal(map) +
                    honorResMapper.getTotal(map) +
                    paperResMapper.getTotal(map) +
                    patentResMapper.getTotal(map) +
                    softwarecopyrightResMapper.getTotal(map);
            result.put(String.valueOf(i), count);
        }
        return result;
    }

    @Override
    public List<String> getDeleteUrl() {
        return provemapper.getDeleteUrl();
    }
}
